function format(time, format) {
    let date = new Date(time);
	let year = date.getFullYear(),
		month = date.getMonth()+1,//月份是从0开始的
		day = date.getDate(),
		hour = date.getHours(),
		min = date.getMinutes(),
		sec = date.getSeconds();
    let preArr = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09"]        
    return format.replace(/yyyy/g,year)
						.replace(/MM/g,preArr[month]||month)
						.replace(/dd/g,preArr[day]||day)
						.replace(/HH/g,preArr[hour]||hour)
						.replace(/mm/g,preArr[min]||min)
                        .replace(/ss/g,preArr[sec]||sec);
}

module.exports = {
    format: format
}